package com.chenbei.common.handler.introspector;

import com.chenbei.common.annotation.Desensitize;
import com.chenbei.common.enums.DesensitizeTypeEnum;
import com.chenbei.common.handler.serializer.DesensitizeSerializer;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.Annotated;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DesensitizeAnnotationInstrospector extends AnnotationIntrospector {

    @Override
    public Version version() {
        return Version.unknownVersion();
    }

    @Override
    public Object findSerializer(Annotated am) {
        Desensitize desensitizeAnnotation = am.getAnnotation(Desensitize.class);
        if (desensitizeAnnotation != null) {
            DesensitizeTypeEnum type = desensitizeAnnotation.type();
            return new DesensitizeSerializer(type);
        }
        return null;
    }
}
